/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.raytracer;

import nu.xom.Element;

/**
 *
 * @author drafkind
 */
public class Texture {
  private Vector3 pigment;
  private double ambient;
  private double diffuse;
  private double specular;
  private double shinyness;
  private Vector3 pigment2;

  private String type;
  
  public Texture() {
    ambient = 0.2;
    diffuse = 1;
    specular = 0.1;
    shinyness = 1;
    normalizeLightingModelComponents();
  }

  public Vector3 getPigment() {
    return pigment;
  }

  public Vector3 getPigmentAt(Vector3 where) {
    if ("checkered".equals(type)) {
      int x = (int) where.getData()[0];
      int y = (int) where.getData()[1];
      int z = (int) where.getData()[2];

      if ((x+y+z) % 2 == 0) {
        return pigment;
      } else {
        return pigment2;
      }
    }
    return pigment;
  }

  public void setPigment(Vector3 value) {
    this.pigment = value;
  }

  public double getAmbient() {
    return ambient;
  }

  public void setAmbient(double ambient) {
    this.ambient = ambient;
    normalizeLightingModelComponents();
  }

  public double getDiffuse() {
    return diffuse;
  }

  public void setDiffuse(double diffuse) {
    this.diffuse = diffuse;
    normalizeLightingModelComponents();
  }

  public double getShinyness() {
    return shinyness;
  }

  public void setShinyness(double shinyness) {
    this.shinyness = shinyness;
  }

  public double getSpecular() {
    return specular;
  }

  public void setSpecular(double specular) {
    this.specular = specular;
    normalizeLightingModelComponents();
  }

  private void normalizeLightingModelComponents() {
    double sum = ambient + diffuse + specular;
    /*ambient /= sum;
    diffuse /= sum;
    specular /= sum;*/
  }

  public Vector3 getPigment2() {
    return pigment2;
  }

  public void setPigment2(Vector3 pigment2) {
    this.pigment2 = pigment2;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }
}